home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / librw / RWTValHashTable.z / RWTValHashTable
Encoding:
Text File  |  1998-10-30  |  11.5 KB  |  265 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))                                    RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWTValHashTable<T> - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/tvhasht.h>
  13.  
  14.  
  15.  
  16.               unsigned hashFun(const T&);
  17.           RWTValHashTable<T> table(hashFun);
  18.  
  19. PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!!
  20.      IIIIffff yyyyoooouuuu ddddoooo nnnnooootttt hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd
  21.      hhhheeeerrrreeee....  OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ttttoooo RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt described in
  22.      the Class Reference.
  23.  
  24.  
  25. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  26.      This class implements a parameterized hash table of types TTTT.  It uses
  27.      chaining to resolve hash collisions.  Duplicates are allowed.  It is a
  28.      vvvvaaaalllluuuueeee based collection: objects are copied in and out of the hash
  29.      buckets. Parameter TTTT represents the type of object to be inserted into
  30.      the table, either a class or fundamental type.  The class TTTT must have:
  31.           well-defined copy semantics (TTTT::::::::TTTT((((ccccoooonnnnsssstttt TTTT&&&&)))) or equivalent);
  32.  
  33.           well-defined assignment semantics (TTTT::::::::ooooppppeeeerrrraaaattttoooorrrr====((((ccccoooonnnnsssstttt TTTT&&&&)))) or
  34.           equivalent);
  35.  
  36.           well-defined equality semantics (TTTT::::::::ooooppppeeeerrrraaaattttoooorrrr========((((ccccoooonnnnsssstttt TTTT&&&&))))).
  37.  
  38.      A user-supplied hashing function for type TTTT must be supplied to the
  39.      constructor when creating a new table.  If TTTT is a Rogue Wave class, then
  40.      this requirement is usually trivial because most Rogue Wave objects know
  41.      how to return a hashing value.  In fact, classes RRRRWWWWCCCCSSSSttttrrrriiiinnnngggg, RRRRWWWWDDDDaaaatttteeee,
  42.      RRRRWWWWTTTTiiiimmmmeeee, and RRRRWWWWWWWWSSSSttttrrrriiiinnnngggg contain static member functions called hhhhaaaasssshhhh that
  43.      can be supplied to the constructor as is.  The function must have
  44.      prototype:.Ex
  45.          unsigned hhhhFFFFuuuunnnn(const T& a);
  46.  
  47.  
  48.  
  49.  
  50.  
  51.      and should return a suitable hash value for the object aaaa. To find an
  52.      object, it is first hashed to determine in which bucket it occurs. The
  53.      bucket is then searched for an object that is equal (as determined by the
  54.      equality operator) to the candidate.  The initial number of buckets in
  55.      the table is set by the constructor.  There is a default value.  If the
  56.      number of items in the collection greatly exceeds the number of buckets
  57.      then efficiency will sag because each bucket must be searched linearly.
  58.      The number of buckets can be changed by calling member function rrrreeeessssiiiizzzzeeee(((()))).
  59.      This is an expensive proposition because not only must all items be
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))                                    RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.      copied into the new buckets, but they must also be rehashed. If you wish
  75.      this to be automatically done, then you can subclass from this class and
  76.      implement your own special iiiinnnnsssseeeerrrrtttt(((()))) and rrrreeeemmmmoooovvvveeee(((()))) functions which perform
  77.      a rrrreeeessssiiiizzzzeeee(((()))) as necessary.
  78.  
  79. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  80.      None
  81.  
  82. EEEExxxxaaaammmmpppplllleeee
  83.               #include <rw/tvhasht.h>
  84.           #include <rw/cstring.h>
  85.           #include <rw/rstream.h>
  86.           main()  {
  87.             RWTValHashTable<RWCString> table(RWCString::hash);
  88.             table.insert("Alabama");   // NB: Type conversion occurs
  89.             table.insert("Pennsylvania");
  90.             table.insert("Oregon");
  91.             table.insert("Montana");
  92.             cout << "The table " <<
  93.               (table.contains("Oregon") ? "does " : "does not ") <<
  94.               "contain Oregon0;
  95.             table.removeAll("Oregon");
  96.             cout << "Now the table "
  97.                  << (table.contains("Oregon") ? "does " : "does not ")
  98.                  << "contain Oregon";
  99.             return 0;
  100.           }
  101.  
  102.  
  103.      Program output
  104.  
  105.               The table does contain Oregon
  106.           Now the table does not contain Oregon
  107.  
  108. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  109.               RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhTTTTaaaabbbblllleeee<T>(unsigned (*hashFun)(const T&),
  110.                              size_t buckets = RWDEFAULT_CAPACITY);
  111.  
  112.  
  113.      Constructs a new hash table.  The first argument is a pointer to a user-
  114.      defined hashing function for items of type TTTT.... The table will initally
  115.      have bbbbuuuucccckkkkeeeettttssss buckets although this can be changed with member function
  116.      rrrreeeessssiiiizzzzeeee(((()))).
  117.  
  118.               RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhTTTTaaaabbbblllleeee<T>(const RWTValHashTable<T>& table);
  119.  
  120.  
  121.      Constructs a new hash table as a copy of ttttaaaabbbblllleeee.  The new table will have
  122.      the same number of buckets as the old table.  Hence, although objects
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))                                    RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.      must be copied into the new table, they will not be hashed.
  141.  
  142. PPPPuuuubbbblllliiiicccc OOOOppppeeeerrrraaaattttoooorrrrssss
  143.               RWTValHashTable&
  144.           ooooppppeeeerrrraaaattttoooorrrr====(const RWTValHashTable<T>&);
  145.  
  146.  
  147.      Sets self to a copy of ttttaaaabbbblllleeee.  Afterwards, the new table will have the
  148.      same number of buckets as the old table.  Hence, although objects must be
  149.      copied into the new table, they will not be hashed.
  150.  
  151. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  152.               void
  153.           aaaappppppppllllyyyy(void (*applyFun)(T&, void*), void* d);
  154.  
  155.  
  156.      Applies the user-defined function pointed to by aaaappppppppllllyyyyFFFFuuuunnnn to every item in
  157.      the table.  This function must have prototype:
  158.  
  159.               void yyyyoooouuuurrrrFFFFuuuunnnn(T& a, void* d);
  160.  
  161.  
  162.  
  163.  
  164.  
  165.      Client data may be passed through as parameter dddd.
  166.  
  167.               void
  168.           cccclllleeeeaaaarrrr();
  169.  
  170.  
  171.      Removes all items from the collection.
  172.  
  173.               RWBoolean
  174.           ccccoooonnnnttttaaaaiiiinnnnssss(const T& val) const;
  175.  
  176.  
  177.      Returns TTTTRRRRUUUUEEEE if the collection contains an item which is equal to vvvvaaaallll.
  178.      Returns FFFFAAAALLLLSSSSEEEE otherwise.  Equality is measured by the class-defined
  179.      equality operator.
  180.  
  181.               size_t
  182.           eeeennnnttttrrrriiiieeeessss() const;
  183.  
  184.  
  185.      Returns the number of items currently in the collection.
  186.  
  187.               RWBoolean
  188.           ffffiiiinnnndddd(const T& target, T& k) const;
  189.  
  190.  
  191.      Returns TTTTRRRRUUUUEEEE if the collection contains an item which is equal to ttttaaaarrrrggggeeeetttt
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))                                    RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.      and puts the matching object into kkkk.  Returns FFFFAAAALLLLSSSSEEEE otherwise and leaves
  207.      kkkk untouched.  Equality is measured by the class-defined equality
  208.      operator.
  209.  
  210.               void
  211.           iiiinnnnsssseeeerrrrtttt(const T& val);
  212.  
  213.  
  214.      Inserts the value vvvvaaaallll into the collection.
  215.  
  216.               RWBoolean
  217.           iiiissssEEEEmmmmppppttttyyyy() const;
  218.  
  219.  
  220.      Returns TTTTRRRRUUUUEEEE if the collection has no items in it, FFFFAAAALLLLSSSSEEEE otherwise.
  221.  
  222.               size_t
  223.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const T& val) const;
  224.  
  225.  
  226.      Returns the number of items in the collection which are equal to vvvvaaaallll.
  227.      Equality is measured by the class-defined equality operator.
  228.  
  229.               RWBoolean
  230.           rrrreeeemmmmoooovvvveeee(const T& val);
  231.  
  232.  
  233.      Removes the first object which is equal to the object aaaa and returns TTTTRRRRUUUUEEEE.
  234.      Returns FFFFAAAALLLLSSSSEEEE if there is no such object.  Equality is measured by the
  235.      class-defined equality operator.
  236.  
  237.               size_t
  238.           rrrreeeemmmmoooovvvveeeeAAAAllllllll(const T& val);
  239.  
  240.  
  241.      Removes all objects which are equal to the object aaaa.  Returns the number
  242.      of objects removed.  Equality is measured by the class-defined equality
  243.      operator.
  244.  
  245.               void
  246.           rrrreeeessssiiiizzzzeeee(size_t N);
  247.  
  248.  
  249.      Changes the number of buckets to NNNN, a relatively expensive operation if
  250.      there are many items in the collection.
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.